/**
 * Create in 2012-4-19.
 */
package kit4j.ui.cs.swing.component;

import java.awt.Point;

import javax.swing.JMenu;


/**
 * 
 * @author MiniKnife
 *
 */
public class RelocatableMenu extends JMenu {

	private static final long serialVersionUID = 1L;
	
	private int menuLocation;
	
	private MenuLocator menuLocationState;
	
	public RelocatableMenu() {
		super();
		init();
	}
	
	public RelocatableMenu(String label) {
		super(label);
		init();
	}
	
	private void init() {
		setMenuLocation(MenuLocator.SOUTH_WEST);
	}
	
	@Override
	protected Point getPopupMenuOrigin() {
		initPopupMenuSize();
		
		return menuLocationState.getMenuOrigin();
	}
	
	private void initPopupMenuSize() {
		getPopupMenu().setVisible(true);
		getPopupMenu().setVisible(false);
	}

	/**
	 * @return the menuLocation
	 */
	public int getMenuLocation() {
		return menuLocation;
	}

	/**
	 * @param menuLocation the menuLocation to set
	 */
	public void setMenuLocation(int menuLocation) {
		this.menuLocation = menuLocation;
		
		menuLocationState = MenuLocator.getMenuLocator(this, menuLocation);
	}

}
